<template>
  <div class="app-container" ref="appContainer">
    <el-form :inline="true" :model="form" ref="form-inline">
      <el-form-item label="批次号" prop="batchNo" :rules="{required: true, message: '批次号为空', trigger: 'blur' }">
          <el-input v-model="form.batchNo" placeholder="批次号"></el-input>
      </el-form-item>
      <el-form-item>
          <el-button type="primary"  @click="search">查询 </el-button>
          <el-button type="info" :disabled="!form.batchNo" @click="downLoad">下载 </el-button>
      </el-form-item>
    </el-form>
    <Table 
        ref="Table" 
        :tableData="tableData" 
        :tableHeadData="tableHeadData" 
        :tableRowClassName="tableRowClassName"
        :total="total"
        v-loading="tableLoading"
        @getList="search" 
    />
      <el-dialog
        :title="dialogTitle"
        :visible.sync="dialogVisible"
        width="1400px">
        <Table 
            ref="dialogTable" 
            :tableData="dialogTableData" 
            :tableHeadData="dialogTableHeadData"
        />
      </el-dialog>  
  </div>
</template>

<script>
import Table from '@/components/table/table.vue';
import { JueceCommon } from './juece.common'
import { batchQuery,batchDetail } from '@/api/user'

import bus from '@/utils/bus.js'
export default {
  components:{
    Table
  },
  data() {
    return {
      form:{
        batchNo:''
      },
      tableData:[],
      total:0,
      dialogTableData:[],
      tableHeadData:[],
      dialogTableHeadData:[],
      tableLoading:false,
      currentPageParams:{
          'pageNum': 1,
          'pageSize': 10
      },
      dialogVisible:false,
      dialogTitle:'',
    }
  },
  created(){
    this.jueceCommon = new JueceCommon(this);
  },
  activated(){
    const { batchNo } = this.$route.query;
    if(batchNo){
      this.form.batchNo = batchNo;
      this.search()
    }
  },
  mounted(){
    //this.search()
   this.watermarkText = localStorage.getItem('userName') || '';
   bus.$on('es_link',(...data) => {
     // console.log('es_link',data)
      this.handelLink(data[0],data[1])

    })
  },
  methods:{
    async handelLink(row,type){
      //console.log('result',row,type)
      const params = {
        type,
        batchId:row.id
        //batchId:278
      };
      this.tableLoading = true;
      const result = await batchDetail(params);
      //console.log('result',result)
      const { data } = result;
      this.dialogTableData = data;

      this.$nextTick(_ =>{
        if(type === 'bzx'){
          this.dialogTitle = '被执行数据';
          this.dialogTableHeadData = this.jueceCommon.tableHead_bzx(data[0]);
        }else if(type === 'ktgg'){
          this.dialogTitle = '开庭数据';
          this.dialogTableHeadData = this.jueceCommon.tableHead_ktgg(data[0]);
        }else if(type === 'laxx'){
          this.dialogTitle = '立案数据';
          this.dialogTableHeadData = this.jueceCommon.tableHead_la(data[0]);
        }else{
          this.dialogTitle = '限高数据';
          this.dialogTableHeadData = this.jueceCommon.tableHead_xzgxf(data[0]);
        }
      })
      this.tableLoading = false;
      this.dialogVisible = true;
      
    },
    async search({ pageSize = 10, pageNum = 1 } = this.currentPageParams){
        const params = {
          rows:pageSize,
          page:pageNum,
          ...this.form
        };
      //console.log('onSubmit',this.form)
       //this.getTableList(this.currentPageParams)
       this.$refs['form-inline'].validate(async(valid) => {
          if (valid) {
            this.tableLoading = true;
            const res = await batchQuery(params);
            const { rows,total } = res.data;
            this.total = total;
            this.tableData = this.jueceCommon.fomatData_ES(rows);
            //this.tableData = this.jueceCommon.fomatData_ES([...data,...data,...data,...data,...data,...data]);
            this.tableHeadData = this.jueceCommon.tableHead_ES(rows[0],this);
            this.tableLoading = false;
           // console.log('res',res);
           
          }
        });
    },
    async downLoad() {
      const url = process.env.VUE_APP_BASE_API + '/batch/export?batchNo=' + this.form.batchNo;
      window.open(url,'_blank')
    },
    tableRowClassName ({row}) { // 点击行获取table的行索引
        if (row.isOK === '通过') {
            return 'current-row';
        }
    },
  }
}
</script>

<style scoped lang="scss">

 ::v-deep .pagination {
  .el-pagination{
    text-align: center;
  }
 }
 ::v-deep .el-table__header{
  .cell{
    padding: 0 5px;
  }
 }
 ::v-deep .el-table__body tr.current-row>td{
      background-color: rgba(204,255,230,.3);
  }
</style>